package com.etcfg.etlaunch.ui;

import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.KeyStroke;

import com.etcfg.etlaunch.ETLauncherApplication;
import com.etcfg.etlaunch.ETServer;

public class CopyServerAction extends AbstractAction {

	private MainWindow mainWindow;
	private ETLauncherApplication application;

	public CopyServerAction(MainWindow mainWindow,
			ETLauncherApplication application) {
		super();
		this.mainWindow = mainWindow;
		this.application = application;
		putValue(NAME, "Copy");
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
				InputEvent.CTRL_DOWN_MASK));

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		ETServer selectedEtServer = mainWindow.getSelectedEtServer();
		if (selectedEtServer != null) {
			StringBuilder builder = new StringBuilder();
			builder.append(selectedEtServer.getIp());
			builder.append(":");
			builder.append(selectedEtServer.getPort());
			if (selectedEtServer.getPassword() != null) {
				builder.append(" ");
				builder.append(selectedEtServer.getPassword());
			}
			mainWindow.setClipboardContents(builder.toString());

		}
	}

}
